<template>
  <div id="box">
    <div class="search_box">
      <div class="search_input">
        <el-select v-model="value" placeholder="名称" />
        <el-date-picker
          v-model="value"
          type="daterange"
          range-separator="~"
          start-placeholder="开始"
          end-placeholder="结束"
        />
        <el-select v-model="value" placeholder="会员" />
      </div>
      <div class="search_btn">
        <el-button type="primary" icon="el-icon-search">{{ $t('ele.btn_search') }}</el-button>
        <el-button icon="el-icon-refresh-right">{{ $t('ele.btn_reset') }}</el-button>
      </div>
    </div>
    <el-button type="primary" style="margin-bottom: 10px;" icon="el-icon-plus" @click="createAvtive">新建</el-button>
    <el-table :data="list" border>
      <el-table-column prop="vipname" label="名称" align="center" />
      <el-table-column prop="vipmobile" label="电话" align="center" />
      <el-table-column prop="vipsex" label="性别" align="center" />
      <el-table-column prop="viptype" label="类型" align="center" />
      <el-table-column prop="vipjs" label="角色" align="center" />
      <el-table-column prop="vipcreate" label="注册时间" align="center" />
      <el-table-column prop="vipjf" label="积分" align="center" />
      <el-table-column prop="vipjb" label="金币" align="center" />
      <el-table-column prop="viprz" label="认证" align="center" />
      <el-table-column prop="username" label="操作" align="center" width="250">
        <template slot-scope="scope">
          <el-button type="text" @click="topup(1,scope.row)">积分充值</el-button>
          <el-button type="text" @click="topup(2,scope.row)">金币充值</el-button>
          <el-button type="text" @click="delitem(scope.row)">删除</el-button>
          <el-button type="text" @click="frozenactive">冻结</el-button>
          <el-button type="text" @click="createAvtive">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 新建 -->
    <el-drawer
      title="新建用户"
      size="40%"
      :visible.sync="createshow"
      :before-close="closecreate"
    >
      <div class="demo-drawer__content" style="padding: 20px 30px; margin-bottom: 50px;">
        <el-form ref="formRef" :model="form" :rules="rules">
          <el-form-item prop="vipname" label="姓名">
            <el-input v-model="form.vipname" />
          </el-form-item>
          <el-form-item prop="vipmobile" label="电话">
            <el-input v-model="form.vipmobile" />
          </el-form-item>
          <el-form-item prop="vipsex" label="性别">
            <el-radio v-model="form.sex" label="1">男</el-radio>
            <el-radio v-model="form.sex" label="2">女</el-radio>
          </el-form-item>
          <el-form-item prop="viptype" label="类型">
            <el-radio v-model="form.viptype" label="1">会员</el-radio>
            <el-radio v-model="form.viptype" label="2">普通用户</el-radio>
          </el-form-item>
          <el-form-item prop="vipjs" label="角色">
            <el-radio v-model="form.vipjs" label="1">消费者</el-radio>
            <el-radio v-model="form.vipjs" label="2">骑手</el-radio>
          </el-form-item>
          <el-form-item prop="vipjf" label="积分">
            <el-input v-model="form.vipjf" />
          </el-form-item>
          <el-form-item prop="vipjb" label="金币">
            <el-input v-model="form.vipjf" />
          </el-form-item>
          <el-form-item prop="viprz" label="姓名">
            <el-upload
              action="https://jsonplaceholder.typicode.com/posts/"
              list-type="picture-card"
            >
              <i class="el-icon-plus" />
            </el-upload>
          </el-form-item>
        </el-form>
      </div>
      <div class="demo-drawer__footer">
        <el-button @click="closecreate">取 消</el-button>
        <el-button type="primary" @click="submitcreate">确 定</el-button>
      </div>
    </el-drawer>
    <!-- 充值 -->
    <el-dialog
      :title="numtype == 1 ? '积分充值':numtype == 2 ? '金币充值' : ''"
      :visible.sync="topupshow"
      width="25%"
      :before-close="close"
    >
      <el-input v-if="numtype == 1" v-model="vipitem.vipjf" type="number" />
      <el-input v-if="numtype == 2" v-model="vipitem.vipjb" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="close">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 冻结 frozen -->
    <el-dialog
      title="冻结账户"
      :visible.sync="frozenshow"
      width="25%"
      :before-close="frozenclose"
    >
      <div style="height:100px">
        <el-radio v-model="frozen" label="1">短期冻结</el-radio>
        <el-radio v-model="frozen" label="2">永久冻结</el-radio>
        <el-date-picker
          v-if="frozen == 1"
          v-model="frozentime"
          style="margin-top: 30px;width: 80%;"
          type="daterange"
          range-separator="~"
          start-placeholder="开始"
          end-placeholder="结束"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="frozenclose">取 消</el-button>
        <el-button type="primary" @click="frozenclose">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: '',
      createshow: false,
      form: {
        vipname: '',
        vipmobile: '',
        vipsex: '',
        viptype: '',
        vipjs: '',
        vipjf: 0,
        vipjb: 0,
        viprz: ''
      },
      rules: {
        vipname: [
          { required: true, message: '请填写姓名', trigger: 'change' }
        ],
        vipmobile: [
          { required: true, message: '请填写电话', trigger: 'change' }
        ],
        vipsex: [
          { required: true, message: '请选择性别', trigger: 'change' }
        ],
        viptype: [
          { required: true, message: '请选择类型', trigger: 'change' }
        ],
        vipjs: [
          { required: true, message: '请选择角色', trigger: 'change' }
        ]
      },
      list: [
        { vipname: '测试', vipmobile: '11111111111', vipsex: '男', viptype: 1, vipjs: 1, vipcreate: '2024-6-6', vipjf: 200, vipjb: 1200, viprz: 1 },
        { vipname: 'luna', vipmobile: '22222222222', vipsex: '女', viptype: 1, vipjs: 0, vipcreate: '2024-6-6', vipjf: 10, vipjb: 1222, viprz: 0 },
        { vipname: '张三', vipmobile: '12345368542', vipsex: '女', viptype: 0, vipjs: 0, vipcreate: '2024-6-6', vipjf: 6, vipjb: 542, viprz: 1 },
        { vipname: 'ja', vipmobile: '8651335434654', vipsex: '男', viptype: 0, vipjs: 1, vipcreate: '2024-6-6', vipjf: 4396, vipjb: 413, viprz: 1 }
      ],
      topupshow: false,
      numtype: 0,
      vipitem: {},
      frozenshow: false,
      frozen: '1',
      frozentime: []
    }
  },
  methods: {
    createAvtive() {
      this.createshow = true
    },
    closecreate() {
      this.createshow = false
    },
    submitcreate() {
      this.$refs['formRef'].validate(valid => {
        if (valid) {
          alert('submit!')
        } else {
          return false
        }
      })
    },
    topup(key, item) {
      this.numtype = key
      this.vipitem = item
      this.topupshow = true
    },
    close() {
      this.numtype = 0
      this.vipitem = {}
      this.topupshow = false
    },
    delitem() {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '已删除'
        })
      })
    },
    frozenactive() {
      this.frozenshow = true
    },
    frozenclose() {
      this.frozenshow = false
    }
  }
}
</script>
<style lang='scss' scoped>
  .el-drawer {
    position: relative;
    .el-input {
      width: 400px;
    }
    .demo-drawer__footer {
      position: absolute;
      bottom:30px;
      right:30px;
    }
    .el-tag{
      margin-right: 20px;
      cursor: pointer;
    }
  }

</style>
